-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix GH-10497: Allow const obj->prop = value #20903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix GH-10497: Allow const obj->prop = value #20903
Conversation
iluuu1994
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @khaledalam! Looks reasonable overall.
Pass type parameter to zend_compile_const() instead of bool use_tmp Check BP_VAR_R/BP_VAR_IS for read mode Remove unnecessary wrapper function Return void instead of zend_op*
Thanks @iluuu1994 for the feedback, all comments addressed. |
|
Cool, thanks @khaledalam! This is a language change and should be discussed on the internals mailing list at least. I think this will impact GH-13800, but that's not a major issue. |
|
Btw, one thing in particular people might object to is: const arrayTest = [1, 2, 3];
arrayTest[] = 4;
var_dump(arrayTest);This becomes valid, but prints: I.e. the assignment has no effect, because it happens on a temporary value. Make sure to mention this in your e-mail to internals. |
|
I've opened an internals thread and sent an email for discussion: https://news-web.php.net/php.internals/129757 |
Description
Fixes #10497 - Allows direct modification of object properties stored in constants.
Problem
Previously, this code would fail with a fatal error:
Solution
Modified the compiler to properly handle ZEND_AST_CONST in variable compilation contexts:
Constants now emit IS_VAR instead of IS_TMP_VAR when used in write contexts
This allows property assignment opcodes to work correctly with constant objects
Tests:
Behavior
Now supports all property operations on constant objects:
The constant reference remains immutable, but the object itself is mutable as expected.